package com.jixi;

import okhttp3.*;

import java.io.IOException;

public class Coze_Chat_TEST {
	public static void main(String[] args) {
		/*
		final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
		
		MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
		String requestBody = "{" +
					"\"bot_id\":\"7480825539104833563\"," +
					"\"user_id\":\"教育局测试账号\"," +
					"\"stream\":false," +
					"\"auto_save_history\":true," +
					"\"additional_messages\":[{" +
						"\"role\":\"user\"," +
						"\"content\":\"我想知道有哪些套餐在售卖。\"," +
						"\"content_type\":\"text\"" +
						"}]" +
				"}";
//		//在Java13及以上的版本中，可以使用文本块（Text Blocks）来构建JSON字符串，就像下面这样：
//		String requestBody = """
//            {
//                "bot_id":"7477123128011931667",
//                "user_id":"教育局测试账号",
//                "stream":false,
//                "auto_save_history":true,
//                "additional_messages":[{
//                    "role":"user",
//                    "content":"Java中int型数据的范围是多少？",
//                    "content_type":"text"
//                }]
//            }
//        """;
		RequestBody body = RequestBody.Companion.create(requestBody, mediaType);
		Request request = new Request.Builder()
				.url("https://api.coze.cn/v3/chat")
				.post(body)
				.addHeader("Content-Type", "application/json")
				.addHeader("Authorization", "Bearer " + "czs_lf9o9jVqBkBUbkVXHbOXZoErA5WVdaYjPlLDz3D5Uh0lRMfLDFJKISftNcDHtDzPT")
				.build();
		
		try (Response response = HTTP_CLIENT.newCall(request).execute()) {
			if (response.isSuccessful()) {
				if (response.body() != null) {
					String str = response.body().string();
					System.out.println(str);
				}
			} else {
				// 输出错误信息
				if (response.body() != null) {
					System.err.println("请求失败: " + response.code() + " " + response.message());
					System.err.println(response.body().string());
				} else {
					System.err.println("请求失败: " + response.code() + " " + response.message());
				}
			}
		} catch (IOException e) {
			// 捕获网络请求过程中可能发生的IO异常
			System.err.println("请求异常: ");
			e.printStackTrace();
		}
		
		*/
	}
}
